import {
  http,
} from '@/utils/request';
import type { Search } from '~/constants/types';

/**
 * 获取拼团分享链接
 */
export function getGroupBuyShare(parentOrderSn: string, skuId: string) {
  return http.request({
    url: `promotion/pintuan/share`,
    method: "GET",
    params: { parentOrderSn, skuId }
  });
}


/**
 * 通过拼团id获取拼团成员列表
 */
export function getGroupBuyUserList(id: string) {
  return http.request({
    url: `/promotion/pintuan/${id}/members`,
    method: "GET",

  });
}


/**
 * 分页获取已参与的砍价活动
 */
export function getBargainedList(params: Search) {
  return http.request({
    url: `/promotion/kanjiaGoods/kanjiaActivity/mine/`,
    method: "GET",
    params
  });
}


/**
 * 获取全部优惠券
 * @param params
 */
export function getAllCoupons(params: any) {
  return http.request({
    url: "/promotion/coupon",
    method: "GET",
    params,
  });
}

// 获取优惠券列表
export function getCouponList(params: any) {
  return http.request({
    url: '/promotion/coupon',
    method: 'GET',
    params,
  })
}

// 获取单个优惠券
export function receiveCoupons(couponId: string | number) {
  return http.request({
    url: `/promotion/coupon/receive/${couponId}`,
    method: 'GET',
  })
}


/**
 * 获取积分商城商品
 * @param params
 */
export function getPointsGoods(params: any) {
  return http.request({
    url: "/promotion/pointsGoods",
    method: "GET",
    params,
  });
}
/**
 * 获取积分商城商品详情
 * @param params
 */
export function getCategoryPointsGoodsDetail(params: any) {
  return http.request({
    url: "/promotion/pointsGoods",
    method: "GET",
    params,
  });
}


/**
 * 获取积分商品详情
 * @param params
 */
export function getPointsGoodsDetail(id: string) {
  return http.request({
    url: "/promotion/pointsGoods/" + id,
    method: "GET",
  });
}


/**
 * 获取积分商城分类
 */
export function getPointsCategory() {
  return http.request({
    url: "/promotion/pointsGoods/category",
    method: "GET",
  });
}

/**
 * 获取拼团列表
 */
export function getGroupBuyList(params: any) {
  return http.request({
    url: "/promotion/pintuan",
    method: "GET",
    params
  });
}

/**
 * 获取砍价
 */
export function getBargainList(params: any) {
  return http.request({
    url: "/promotion/kanjiaGoods",
    method: "GET",
    params
  });
}

/**
 * 分页获取砍价商品
 * @param params
 */
export function getBargainDetail(id: string | number) {
  return http.request({
    url: `/promotion/kanjiaGoods/${id}`,
    method: "GET",
  });
}

/**
 * 分页获取砍价活动-帮砍记录
 */
export function getBargainLog(params: any) {
  return http.request({
    url: `/promotion/kanjiaGoods/getKanjiaActivity/logs`,
    method: "GET",
    data: params,
  });
}


/**
 * 分页获取砍价活动-帮砍记录
 */
export function helpBargain(kanJiaActivityId: string | number) {
  return http.request({
    url: `promotion/kanjiaGoods/help/${kanJiaActivityId}`,
    method: "POST",
  });
}



/**
 * 获取砍价活动
 * @param params
 */
export function getBargainActivity(params: any) {
  return http.request({
    url: `/promotion/kanjiaGoods/getKanjiaActivity`,
    method: "POST",
    params,
  });
}

/**
 * 发起砍价活动
 * @param params
 */
export function launchBargain(params: any) {
  return http.request({
    url: `/promotion/kanjiaGoods`,
    method: "POST",
    header: { "content-type": "application/x-www-form-urlencoded" },
    data: params,
  });
}



/**
 * 获取秒杀时间线
 */
export function getSeckillTimeLine() {
  return http.request({
    url: "/promotion/seckill",
    method: "GET",
  });
}

/**
 * 根据秒杀时间段获取秒杀商品
 */
export function getSeckillTimeGoods(timeline: string) {
  return http.request({
    url: `/promotion/seckill/${timeline}`,
    method: "GET",
  });
}

/**
 * /promotion/coupon-activity/activity
 * 获取优惠券活动
 */
export function getCouponActivity() {
  return http.request({
    url: '/promotion/coupon/activity',
    method: 'GET'
  })
}